package com.ruoyi.system.service.news.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.ruoyi.system.domain.news.NewsRelatedDownload;
import com.ruoyi.system.domain.news.query.NewsRelatedDownloadQuery;
import com.ruoyi.system.domain.news.vo.NewsRelatedDownloadVo;
import com.ruoyi.system.domain.news.vo.NewsRelatedDownloadVo;
import com.ruoyi.system.mapper.news.NewsRelatedDownloadMapper;
import com.ruoyi.system.service.news.NewsRelatedDownloadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class NewsRelatedDownloadServiceImpl extends ServiceImpl<NewsRelatedDownloadMapper, NewsRelatedDownload>
        implements NewsRelatedDownloadService {

    @Override
//    @DataScope(deptAlias = "t",userAlias = "t")
    public List<NewsRelatedDownloadVo> getNewsRelatedDownloadList(NewsRelatedDownloadQuery newsRelatedDownloadQuery) {
        if (newsRelatedDownloadQuery.getIfPage()) {
            PageHelper.startPage(newsRelatedDownloadQuery.getPageNum(), newsRelatedDownloadQuery.getPageSize());
        }
        List<NewsRelatedDownloadVo> newsRelatedDownloadVoList = baseMapper.getNewsRelatedDownloadList(newsRelatedDownloadQuery);
        if (!newsRelatedDownloadVoList.isEmpty() && newsRelatedDownloadQuery.getId() == null) {
            for (NewsRelatedDownloadVo newsRelatedDownloadVo:newsRelatedDownloadVoList) {
                newsRelatedDownloadVo.setContent(null);
            }
        }
        return newsRelatedDownloadVoList;
    }
}
